package me.zhengjie.modules.system.domain;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import me.zhengjie.base.BaseEntity;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Objects;

/**
 * 场景风险类别表
 *
 * @author guoyuan
 * @version 1.0.0
 * @since 1.0.0
 */
@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "st_safe_risk_type")
public class SafeRiskType extends BaseEntity implements Serializable {

    @Id
    @NotNull(groups = Update.class)
    @ApiModelProperty(value = "ID", hidden = true)
    @GeneratedValue(generator = "type_id")
    @GenericGenerator(name = "type_id", strategy = "uuid")
    @Column(name = "id", length = 32, unique = true, nullable = false)
    private String id;

    @NotBlank
    @ApiModelProperty(value = "场景类型0:业务 1:功能")
    private String sceneType;

    @NotBlank
    @ApiModelProperty(value = "名称路径")
    private String path;

    @ApiModelProperty(value = "段级")
    private String level;

    @NotBlank
    @ApiModelProperty(value = "节点名称")
    private String name;

    @ApiModelProperty(value = "父节点id(根节点为空)")
    private String parentId;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        SafeRiskType that = (SafeRiskType) o;
        return Objects.equals(id, that.id) &&
                Objects.equals(sceneType, that.sceneType) &&
                Objects.equals(path, that.path) &&
                Objects.equals(level, that.level) &&
                Objects.equals(name, that.name) &&
                Objects.equals(parentId, that.parentId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, sceneType, path, level, name, parentId);
    }

    public SafeRiskType(@NotBlank String sceneType, @NotBlank String path, String level, @NotBlank String name, String parentId) {
        this.sceneType = sceneType;
        this.path = path;
        this.level = level;
        this.name = name;
        this.parentId = parentId;
    }
}
